package Thread;

/**
 * 使用饿汉模式实现单例模式
 */
class SingletonEager{
   private static SingletonEager instance = new SingletonEager();
   public  static  SingletonEager getInstance(){
       return  instance;
   }
    private SingletonEager(){
        System.out.println("SingletonEager 被创建");
    }
   public void ShowMassage(){
        System.out.println("展示小野猫对我的爱，她已经很快把心给我了");
    }
}
class  Singleton {
    String name;
    int age;
    private  static  Singleton instance = new Singleton();
    public  static  Singleton getInstance(){
        return instance;
    }
    public Singleton(){

    }
    public   Singleton(int n){

    }

}
public class Demo24 {
    public static void main(String[] args) {
        SingletonEager s1 = SingletonEager.getInstance();
        SingletonEager s2 = SingletonEager.getInstance();
        System.out.println("s1和s2是否为同一个实例:"+(s1==s2));
        s1.ShowMassage();
    }
    public static void main1(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1==s2);
        //Singleton t = new Singleton();

    }
}
